<html>
<head><meta charset="utf-8"><title>how to decode `String` from crate binary&#x27;s metadata · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/how.20to.20decode.20.60String.60.20from.20crate.20binary&#x27;s.20metadata.html">how to decode `String` from crate binary&#x27;s metadata</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="219189842"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/how%20to%20decode%20%60String%60%20from%20crate%20binary%27s%20metadata/near/219189842" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jay Somedon <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/how.20to.20decode.20.60String.60.20from.20crate.20binary&#x27;s.20metadata.html#219189842">(Dec 08 2020 at 10:09)</a>:</h4>
<p>I am trying to check what version of rustc was used to compile certain crate. So far I kinda see that the <code>.rustc</code> section encoded a <code>String</code> of this info at offset 12(metadata header is 8 bytes, and crate root position info is 4 bytes) then I don't know excat how many bytes to look at from here, and decode those bytes in what encoding scheme? Anyone know how this works?</p>
<p>I also navigated through the <code>rustc_serialize</code> crate to make some sense of this process, and I don't really get what <code>Lazy&lt;T&gt;</code> is? It says it remembers previous node, and nodes are in postfix tree, and the tree is metadata as a whole, but it seems kinda too abstract to me. Would someone explain those with, you know, potentially some example? <span aria-label="sweat smile" class="emoji emoji-1f605" role="img" title="sweat smile">:sweat_smile:</span></p>



<a name="219193033"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/how%20to%20decode%20%60String%60%20from%20crate%20binary%27s%20metadata/near/219193033" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/how.20to.20decode.20.60String.60.20from.20crate.20binary&#x27;s.20metadata.html#219193033">(Dec 08 2020 at 10:50)</a>:</h4>
<p>The metadata starts with 4 bytes that should be equal to <code>b"rust"</code>, then 4 bytes for the crate root position. Followed by that is 4 bytes with the length of the rustc version string. Next comes the rustc version string itself encoded as UTF-8.</p>



<a name="219193452"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/how%20to%20decode%20%60String%60%20from%20crate%20binary%27s%20metadata/near/219193452" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jay Somedon <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/how.20to.20decode.20.60String.60.20from.20crate.20binary&#x27;s.20metadata.html#219193452">(Dec 08 2020 at 10:55)</a>:</h4>
<p>Ah, hey, many thanks for this and on github!</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>